<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑推广策略</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var promotionId = <%=params[:id]%>;
        var name = Ext.create('Ext.form.field.Text', {
          fieldLabel: '名称',
          allowBlank: false,
          blankText: "推广策略名称不能为空",
          name: 'name',
          anchor: '95%'
        });

        var beginDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '活动日期',
          name: 'begin_date',
          id: 'begin_date',
          format: 'Y-m-d', //格式化日期
          width: '100',
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          
          anchor: '90%',
          vtype: 'daterange',
          endDateField: 'end_date'
        });
        var endDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '至    ',labelWidth:30,
          name: 'end_date',
          id: 'end_date',
          format: 'Y-m-d', //格式化日期
          width: '100',
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          
          anchor: '90%',
          vtype: 'daterange',
          startDateField: 'begin_date'
        });

        var desc = Ext.create('Ext.form.TextArea', {
          fieldLabel: '描述',
          name: 'description',
          height:160,
          anchor: '95%'
        });

        var editPromotionForm = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 55,
            labelAlign: 'right'
          },
          frame:true,
          url: '/promotion/update?id=' + promotionId,
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'name'
            }, {
              name: 'begin_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'end_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'description'
            }]),
          bodyStyle:'padding:5px 5px 0',
          width: 600,
          //height:300,
          items: [{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: 1,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [name]
                }]
            },{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: .5,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [beginDate]
                },{
                  columnWidth: .5,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [endDate]
                }]
            },{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: 1,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [desc]
                }]
            }],
          buttons: [{
              text: '提交',
              handler: function(){
                // check form value
                if (editPromotionForm.form.isValid()) {
                  editPromotionForm.form.submit({
                    method: 'GET',
                    success: function(result, response){
                      if (response.result.info == "成功") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        editPromotionWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text: '取消',
              handler: function(){
                editPromotionWin.destroy();
              }
            }]
        });
        //编辑前，把数据引入到表单中。
        // load form and assign value to fields
        editPromotionForm.form.load({
          url: '/promotion/getPromotionById?id=' + promotionId,
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
            
        editPromotionForm.render('edit_promotion_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_promotion_form"></div>
  </body>
</html>
